<template>
  <div class="info">
    <div class="tab">
      <el-form ref="form" :model="form" label-width="100px">
        <el-row>
          <el-col :span="10">
            <el-form-item label="商品名">
              <el-input v-model="form.shopName"></el-input>
            </el-form-item>
            <el-form-item label="供应商">
              <el-input v-model="form.storePersonl"></el-input>
            </el-form-item>
            <el-form-item label="店铺分类">
              <el-select v-model="form.shopClassifyId">
                <el-option
                  v-for="item in shopClassify"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="缩略图">
              <el-upload
                action=""
                list-type="picture-card"
                :http-request="upLoad"
                :before-upload="beforeAvatarUpload"
                :on-preview="handlePictureCardPreview"
                :on-remove="handleRemove"
                :file-list="fileList"
                :limit="10"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
              <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt="" />
              </el-dialog>
            </el-form-item>
            <el-form-item label="商品简介">
              <el-input v-model="form.txtInfo"></el-input>
            </el-form-item>
            <el-form-item label="商品原价">
              <el-input v-model="form.originalPrice"></el-input>
            </el-form-item>
            <el-form-item label="商品销量">
              <el-input v-model="form.num"></el-input>
            </el-form-item>
            <el-form-item label="商品描述">
              <el-input v-model="form.description"></el-input>
            </el-form-item>
            <el-form-item label="一级分类">
              <el-select v-model="form.shopClassifyId">
                <el-option
                  v-for="item in shopClassify"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="二级分类">
              <el-select v-model="form.shopClassifyId">
                <el-option
                  v-for="item in shopClassify"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="店铺状态">
              <el-select v-model="form.shopStateId">
                <el-option
                  v-for="item in shopState"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item>
          <el-button type="primary" @click="handleSubmit">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      page: {
        total: 0,
        pageNum: 1, // 当前页数
        pageSize: 10, // 每页的条数
      },
      form: {
        shopName: "",
        storePersonl: "",
        txtInfo: "",
        originalPrice: "",
        num: "",
        description: "",
        shopClassifyId: 1,
        shopStateId: 1,
      },
      shopState: [
        { id: 1, name: "启用" },
        { id: 2, name: "禁用" },
      ],
      shopClassify: [
        { id: 1, name: "健康养生" },
        { id: 2, name: "酒店民宿" },
      ],
      fileList: [],
      fileListId: [],
      dialogImageUrl: "",
      dialogVisible: false,
    };
  },
  methods: {
    handleSubmit() {},
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    //门头照
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    //删除门头照
    handleRemove(file) {
      this.fileListId.forEach((item, index) => {
        if (file.name === item.name) {
          this.fileListId.splice(index, 1);
        }
      });
    },
    //上传门头照
    upLoad(file) {
      console.log(file);
    },
  },
  created() {
    console.log(this.$route);
  },
};
</script>

<style lang="scss" scoped>
.tbImg1 {
  width: 100%;
  height: 100%;
  border-radius: 8px;
}
.slt {
  width: 50px;
  height: 36px;
  margin: 0 auto;
  .tbImg {
    width: 50px;
    height: 36px;
    border-radius: 8px;
  }
}
.info {
  .title {
    font-size: 16px;
    margin-bottom: 13px;
  }
  .tab {
    background-color: #fff;
    padding: 20px;
    box-sizing: border-box;
  }
}
.pagination {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}
/deep/.el-breadcrumb__inner {
  cursor: pointer !important;
}
/deep/.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
}
.avatar {
  width: 80px;
  height: 80px;
  display: block;
}
/deep/.el-upload--picture-card {
  width: 90px;
  height: 90px;
  line-height: 90px;
}
/deep/.el-upload-list__item {
  width: 90px !important;
  height: 90px !important;
  border: 0 !important;
}
</style>
